﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace f1
{
    
    public partial class Form_select : Form
    {
        int way;
        string search;
        public bool open;
        public Form_select()
        {
            
            InitializeComponent();
            cb_way.Items.Add("全部");
            cb_way.Items.Add("按订单号查找");
            cb_way.Items.Add("按产品查找");
            cb_way.Items.Add("按顾客查找");
            cb_way.Items.Add("按金额查找");
            open = true;
        }

        
        private void cb_way_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cb_way.Text == "全部")
            {
                this.way = 1;
                content_txt.Clear();
                content_txt.ReadOnly = true;
            }else if(cb_way.Text== "按订单号查找")
            {
                this.way = 2;
                
                content_txt.ReadOnly = false;
            }else if (cb_way.Text == "按产品查找")
            {
                this.way = 3;
                content_txt.ReadOnly = false;
            }else if (cb_way.Text == "按顾客查找")
            {
                this.way = 4;            
                content_txt.ReadOnly = false;
            }
            else if (cb_way.Text == "按金额查找")
            {
                this.way = 5;
                content_txt.ReadOnly = false;
            }
            else
            {
                this.way = 0;
            }
        }

        private void content_txt_TextChanged(object sender, EventArgs e)
        {
            this.search = content_txt.Text;
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            if (this.way == 1)
            {
                OrderService.selectAll();
                Close();
            }
            else if (this.way == 2)
            {
                try
                {
                    int n = Convert.ToInt32(content_txt.Text);
                    OrderService.selectNum(n);
                    Close();
                }
                catch
                {
                    DialogResult result = MessageBox.Show("查找失败，订单号必须是正整数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }                            
            }else if (this.way == 3)
            {
                OrderService.selectPro(content_txt.Text);
                Close();
            }
            else if (this.way == 4)
            {
                OrderService.selectCus(content_txt.Text);
                Close();
            }
            else if (this.way == 5)
            {
                try
                {
                    double p = Convert.ToDouble(content_txt.Text);
                    OrderService.selectPri(p);
                    open = false;
                    Close();
                }
                catch
                {
                    DialogResult result = MessageBox.Show("查找失败，金额必须是数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
            else
            {
                DialogResult result = MessageBox.Show("查找失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
